package sz.szsmk.citizencard.mvp.presenter;

import android.util.Log;

import com.google.gson.Gson;

import javax.inject.Inject;

import rx.Subscription;
import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.bean.request.CakeCardBeanReq;
import sz.szsmk.citizencard.model.network.bean.request.CheckVirCakeBeanReq;
import sz.szsmk.citizencard.model.network.bean.request.IBaseRequest;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.CakeBalanceBeanRes;
import sz.szsmk.citizencard.model.network.bean.response.CakeQRBeanRes;
import sz.szsmk.citizencard.model.network.bean.response.CheckVirCakeBeanRes;
import sz.szsmk.citizencard.model.network.bean.response.GestureValidBean;
import sz.szsmk.citizencard.model.network.bean.response.NoticeMainres;
import sz.szsmk.citizencard.model.network.bean.response.QueryUserCardRes;
import sz.szsmk.citizencard.mvp.IPayCodeMvpView;
import sz.szsmk.citizencard.mvp.contract.INewsContact;
import sz.szsmk.citizencard.mvp.contract.IPasAdminContact;
import sz.szsmk.citizencard.mvp.dzsmkpresenter.AppBasePresenter;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.AndroidUtils;
import sz.szsmk.citizencard.util.Constant;

/**
 * author : hyt
 * date : 2020/5/20
 * description :
 */
public class PayCodePresenter extends AppBasePresenter<IPayCodeMvpView> {

    private NetworkDateSources mNetworkDateSource;

    @Inject
    public PayCodePresenter() {
        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    public void queryCakeBalance(String cakecode){
        CakeCardBeanReq cakeCardBeanReq = new CakeCardBeanReq();
        cakeCardBeanReq.setCard_no(cakecode);
        mNetworkDateSource.queryCakeBalance(cakeCardBeanReq, new SubscribeResult<CakeBalanceBeanRes>() {
            @Override
            protected void onOk(CakeBalanceBeanRes response) {
                getMvpView().queryCakeBalanceSuccess(response);
            }

            @Override
            protected void onFailure(CakeBalanceBeanRes response) {
               getMvpView().fail(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    public void getPayCode(String cakecode){
        CakeCardBeanReq cakeCardBeanReq = new CakeCardBeanReq();
        cakeCardBeanReq.setCard_no(cakecode);
        cakeCardBeanReq.setChannelId("ZHSZ");
        cakeCardBeanReq.setLat("31.320565");
        cakeCardBeanReq.setLnt("120.676979");
        cakeCardBeanReq.setCount("1");
        cakeCardBeanReq.setTimestamp(String.valueOf(System.currentTimeMillis()));
        cakeCardBeanReq.setAccessToken(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));
        cakeCardBeanReq.setDeviceId(AndroidUtils.getAndroidId(DaggerApplication.getIns()));

        mNetworkDateSource.getPayCode(cakeCardBeanReq, new SubscribeResult<CakeQRBeanRes>() {
            @Override
            protected void onOk(CakeQRBeanRes response) {
                getMvpView().onPayCodeSuccess(response);

            }

            @Override
            protected void onFailure(CakeQRBeanRes response) {
                getMvpView().fail(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    //查询是否开通    这里直接在当前页面查询卡号
    public void getIsOpenPayCode(){
        CheckVirCakeBeanReq checkVirCakeBeanReq = new CheckVirCakeBeanReq();
        checkVirCakeBeanReq.setVirType(8000);
        checkVirCakeBeanReq.setAccessToken(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));
        mNetworkDateSource.getIsOpenPayCode(checkVirCakeBeanReq, new SubscribeResult<CheckVirCakeBeanRes>() {
            @Override
            protected void onOk(CheckVirCakeBeanRes response) {
                getMvpView().onIsOpenPayCodeSuccess(response);
            }

            @Override
            protected void onFailure(CheckVirCakeBeanRes response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

}
